import java.util.Scanner;
import java.util.Arrays;

public class Question4 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.println("请输入数组初始容量：");
        int capacity = in.nextInt();
        in.nextLine();

        int[] array = new int[capacity];
        boolean isFull = false;
        int nums = 0; //定义已存储量
        String instruct; //保存是否继续输入的指令

        while(!isFull) {

            System.out.println("请输入一个数组元素");
            array[nums] = in.nextInt();
            in.nextLine();
            nums++;

            // 若需扩容
            if(nums >= array.length * 4 / 5) {
                // 扩容
                capacity = capacity * 3 / 2;
                int[] new_array = new int[capacity];
                // 转移数据
                for(int i=0; i<array.length; i++) {
                    new_array[i] = array[i];
                }
                array = new_array;

                System.out.println("数组已扩容，当前数组为：" +  Arrays.toString(array));
            }else{
                System.out.println("当前数组为：" + Arrays.toString(array));
            }

        }

    }
}
